vcCollisionDetector
vcCollisionDetector is a layout item used for detecting the collision of objects in the 3D world. A collision test can detect a collision using geometry in different nodes and/or a bound box defined by two corner points.
See in: Overview
Module: vcCore
Parent: vcLayoutItem
Children -
Referenced by: -
Properties
Learn how to use properties here. The properties are also inherited from the parent class.
| Name | Type | Access | Description |
| Active | Boolean | RW | Gets or sets a value indicating whether this collision detector is actively testing collisions. |
| CollisionMaterial | vcMaterial | RW | Gets or sets material of the collided node unless NodeACollisionMaterialA or/and NodeACollisionMaterialB were specified. |
| DisplayMinimumDistance | Boolean | RW | Gets or sets a value indicating whether to display the detected minimum distance between object in the 3D world. The minimum distance is shown for collision tests that use a distance tolerance. |
| IgnoreClosestNodes | Boolean | RW | Gets or sets a value indicating whether this detector ignores collisions between two nodes if a node is either parent or child to the other node. This can be used to test self-collision of a component. Default value is False. |
| IgnoreDifferentComponents | Boolean | RW | Gets or sets a value indicating whether this detector ignores collisions between nodes when they are on different components. This can be used to test multiple self-collisions of components. Default value is False. |
| NodeACollisionMaterial | vcMaterial | RW | Gets or sets material of the collided node A. This property will define the node A material over CollisionMaterial. |
| NodeBCollisionMaterial | vcMaterial | RW | Gets or sets material of the collided node B. This property will define the node B material over CollisionMaterial. |
| NodeListA | list | RW | Gets or sets a list of nodes to test for collisions against NodeListB. Setting value will clear existing list and fill with the given one. |
| NodeListB | list | RW | Gets or sets a list of nodes to test for collisions against NodeListA. Setting value will clear existing list and fill with the given one. |
| Tolerance | Real | RW | Gets or sets a distance tolerance for detecting collisions before objects in the test collide with one another.See moreNote that if Tolerance is set to zero, a simplified collision detection algorithm is used. This algorithm does not detect collisions if one geometry is completely enclosed by the other, so for example, if the bounding box surfaces do not intersect. |
| UseColliders | Boolean | RW | Gets or sets a value indicating whether colliders are used in collision detection.See moreWhen enabled, collision detection will prioritize using the colliders associated with the included nodes. If no colliders are present, the node's geometry will be used as a fallback for collision detection. |
Methods
Learn how to use methods here. The methods are also inherited from the parent class.
| Name | Return Type | Parameters | Description |
| testBBoxCollisions | list | vcCollisionTestMethod method, vcVector corner1, vcVector corner2, Optional Keyword[transformation = vcMatrix], Optional Keyword[tolerance = Real] | Tests collision between NodeListA and a bound box defined by given corner points. An optional transformation argument can be given to transform the bound box using World coordinates. See moreParameters: method (vcCollisionTestMethod): Method to use for the collision detection. corner1 (vcVector): First corner point of the bound box. corner2 (vcVector): Second corner point of the bound box. Optional: transformation (vcMatrix): Matrix for the transformation. Optional: tolerance (float): Collision tolerance, if no tolerance is given, test uses tolerance value from Tolerance property. Returns: list[vcCollisionRecord]: List of vcCollision records that contain collisions based on the testing method. Empty if there were no collisions. |
| testCollisions | list | vcCollisionTestMethod method, Optional Keyword[tolerance = Real] | Tests collision between NodeListA and NodeListB.See moreParameters: method (vcCollisionTestMethod): Method to use for the collision detection. Optional: tolerance (float): Collision tolerance, if no tolerance is given, test uses tolerance value from Tolerance property. Returns: list[vcCollisionRecord]: List of vcCollision records that contain collisions based on the testing method. Empty if there were no collisions. |
| testMinimumDistance | list | Optional Keyword[tolerance = Real] | Tests collision with a given tolerance value.See moreParameters: Optional: tolerance (float): Collision tolerance, if no tolerance is given, test uses tolerance value from Tolerance property. Returns: list[vcCollisionRecord]: List of vcCollision records that contain collisions based on the testing method. Empty if there were no collisions. |
Events
Learn how to use events here. The events are also inherited from the parent class.
| Name | Parameters | Description |
| OnCollision | vcCollisionDetector detector, list[vcCollisionRecord] collisionRecords | Triggered when a collision is detected and test is active.See moreParameters: detector (vcCollisionDetector): Detector that contains collision. collisionRecords (list[vcCollisionRecord]): List of vcCollisionRecord that produced event. |
Example: Detect Gripper Collision
"""This example shows how to detect if gripper (or anything the gripper is holding) collides with an object in 3D world.""" import vcCore as vc gripper_node = vc.getComponent() # This script is located in a gripper component world = vc.getWorld() detector = None async def OnRun(): global detector detector = world.createLayoutItem(vc.vcLayoutItemType.COLLISION_DETECTOR) gripper_entry = vc.vcNodeListEntry.new() gripper_entry.Node = gripper_node gripper_entry.Scope = vc.vcNodeListEntryScope.TREE gripper_entry.Type = vc.vcNodeListEntryType.INCLUDE detector.NodeListA = [gripper_entry] # Gripper and its children world_entry = vc.vcNodeListEntry.new() world_entry.Node = world world_entry.Scope = vc.vcNodeListEntryScope.TREE world_entry.Type = vc.vcNodeListEntryType.INCLUDE detector.NodeListB = [world_entry] # All nodes in world while True: # Test collision every 0.01 seconds await vc.delay(0.01) hit = detector.testCollisions(vc.vcCollisionTestMethod.FIRST_COLLISION) if hit: print('collision detected') def OnReset(): global detector if detector: detector.delete() # Remove vcCollisionDetector layout item on simulation reset detector = None